package com.ant.xmla.datacrawling.controller;


import com.alibaba.fastjson.JSONObject;
import com.ant.xmla.datacrawling.service.DownAudioBookService;
import com.ant.xmla.datacrawling.utils.cache.RedisUtil;
import com.ant.xmla.datacrawling.utils.http.HttpClientUtils;
import com.ant.xmla.datacrawling.utils.result.ResultUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * Created by IntelliJ IDEA.
 *
 * @Author 中国蚂蚁技术有限公司
 * @create 2020/9/5 20:00
 */
@RestController
@RequestMapping("DownAudioBook")
public class DownAudioBook {

    private static ResultUtils result = new ResultUtils();

    @Resource
    private DownAudioBookService downAudioBookService;

    @RequestMapping("downAudioBookInfo")
    public ResultUtils downAudioBookInfo(){
        return downAudioBookService.downAudioBookLiterature();
    }

    @RequestMapping("downAudioBookSection")
    public ResultUtils downAudioBookSection(){
        return downAudioBookService.downAudioBookSection();
    }

    @RequestMapping(value = "downAudioBookPageC",method = RequestMethod.GET)
    public ResultUtils downAudioBookPageC(@RequestParam("tackId") Integer tackId) throws Exception {
        return downAudioBookService.downAudioBookPage(tackId);
    }

    @RequestMapping(value = "downAudioBookParam" ,method = RequestMethod.POST)
    @ResponseBody
    public ResultUtils downAudioBookParam(@RequestBody String param){
        String param1 = param.substring(param.indexOf("=") + 1);
        Integer albumId = downAudioBookService.downAudioBookOne(param1);
        try {
            return  downAudioBookService.downAudioBookPage(albumId);
        } catch (Exception e) {
            e.printStackTrace();
            result.setCode("500");
            result.setMessage("下载失败");
            result.setResultCode(500);
            result.setResult(e.getMessage());
        }
        return result;
    }

    @RequestMapping("getToken")
    @ResponseBody
    public String getToken(){
        String token = HttpClientUtils.getToken();
        return token;
    }
}
